﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.Entity;

namespace DAO
{
    
    public class CustomerDao
    {
        public CustomerDao()
        {
            SqlHelper sql = new SqlHelper();
        }

        public DataTable getCustomers()
        {
            return SqlHelper.ExecuteDataTable("GET_ALL_CUSTOMER", CommandType.StoredProcedure);
        }

        public DataTable getremindHist(int id)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_REMIND_HIS", CommandType.StoredProcedure,
                "@ID", id);
        }

        public bool deteteCustomer(List<int> ListId)
        {
            try
            {
                SqlTransaction sqlTransaction;
                SqlConnection con = new SqlConnection(SqlHelper.ConnectString);
                con.Open();
                sqlTransaction = con.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    foreach (int id in ListId)
                    {
                        if(!SqlHelper.ExecuteNonQuery("DELETE_CUSTOMER", CommandType.StoredProcedure,
                           "@ID", id))
                        {
                            sqlTransaction.Rollback();
                            return false;
                        }
                    }
                    sqlTransaction.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    sqlTransaction.Rollback();
                    return false;
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.ToString());
                return false;
            }
        }
    }
}
